<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>添加活码</title>
<meta name="renderer" content="webkit" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1" />
<link href="http://layui.hcwl520.com.cn/layui-v2.4.5/css/layui.css?v=201811010202" rel="stylesheet"></link>
</head>
<body>
	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  		<legend>添加用户</legend>
	</fieldset>
	<form class="layui-form"  >
				<div class="layui-form-item" >
					<label class="layui-form-label">邮箱</label>
					<div class="layui-input-block">
						<input type="text"  placeholder="请输入邮箱"
							autocomplete="off" class="layui-input" lay-verify="required|email" id="email" name="email" />
					</div>
				</div>
				<div class="layui-form-item" >
					<label class="layui-form-label">密码</label>
					<div class="layui-input-block">
						<input type="text"  placeholder="请输入密码"
							autocomplete="off" class="layui-input" lay-verify="required|pass" id="password" name="password"  />
					</div>
				</div>
				<div class="layui-form-item" >
					<label class="layui-form-label">是否为金主</label>
					 <div class="layui-input-block">
						 <input type="checkbox"  lay-filter="switchType"  lay-skin="switch" lay-text="金主|穷逼"  >
						 <input type="hidden"  name="type" id="type"  value="1"/>
					</div>
				</div>
			    <div class="layui-input-block" style="display: none">
			      <button class="layui-btn" lay-submit="" lay-filter="add" id="userSubmint" >立即提交</button>
			      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
   				 </div>
			</form>		
</body>
<script type="text/javascript" src="http://layui.hcwl520.com.cn/jquery/jquery-3.3.1.min.js?v=201804251754"></script>
<script type="text/javascript" src="http://layui.hcwl520.com.cn/layui-v2.4.5/layui.all.js?v=201811010202"></script>
<script>
layui.use('form', function(){
	  var form = layui.form; 
	  form.on('switch(switchType)', function(data){
		  	if(!this.checked){
		  		$("#type").val(1);
		  	}else{
		  		$("#type").val(2);
		  	}
		  });
	  form.verify({
		    pass: [
		      /^[\S]{6,12}$/
		      ,'密码必须6到12位，且不能出现空格'
		    ]
	  });
	  form.render();
	  form.on('submit(add)', function(data){
	    $.ajax({
            //几个参数需要注意一下
                type: "POST",//方法类型
                url: "addUser" ,//url
                data: JSON.stringify(data.field),
                contentType: 'application/json',
                success: function (result) {
                    if (result == "success") {
						parent.layer.msg('添加成功', {
							icon : 6,
						});
						parent.layer.closeAll('iframe'); 
                    }else{
                    	parent.layer.msg('出现网络故障', {
							icon : 5,
						});
						parent.layer.closeAll('iframe'); 
                    }
                },
                error : function() {
                    layer.alert("异常");
                }
            });
	      return false;
	  });
});	

</script>
</html>

